//
//  MCRechargeFooterView.m
//  TLYL
//
//  Created by MC on 2017/6/13.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCRechargeFooterView.h"
#define L_SPACE 15
#define UILABEL_LINE_SPACE 5
#define UILABEL_Kern_SPACE 0.1
#define TIP @"温馨提示：\n1.点击确认充值按钮后会通过手机浏览器进入充值页面；\n2.充值完成后，重新进入APP查看余额；\n3.请在30分钟内完成充值"
@interface MCRechargeFooterView ()
@property (nonatomic,strong)UIButton * btn_recharge;
@property (nonatomic,strong) UILabel * lab_tip;
@end

@implementation MCRechargeFooterView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    self.backgroundColor=[UIColor clearColor];
    //充值
    _btn_recharge=[[UIButton alloc]init];
    [self setFooter:_btn_recharge];
    
    _lab_tip=[[UILabel alloc]init];
    _lab_tip.font=[UIFont systemFontOfSize:12];
    [self addSubview:_lab_tip];
    _lab_tip.numberOfLines=0;
    _lab_tip.textColor=RGB(136,136,136);
    [self setLabelSpace:_lab_tip withValue:TIP withFont:[UIFont systemFontOfSize:10]];
    
    [_lab_tip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(L_SPACE);
        make.right.equalTo(self.mas_right).offset(-L_SPACE);
        make.top.equalTo(self.mas_top).offset(80);
    }];
    
    
}


/*
 * 点击确认充值
 */
-(void)action_Recharge{
    
    if ([self.delegate respondsToSelector:@selector(performRecharge)]) {
        [self.delegate performRecharge];
    }
    
}


-(void)setFooter:(UIButton *)btn{
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitle:@"立即充值" forState:UIControlStateNormal];
    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    btn.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    btn.backgroundColor =MC_THEME_COLOR;
    //    [btn setBackgroundImage:[UIImage imageNamed:@"Button_Determine"] forState:UIControlStateNormal];
    //    [btn setImage:[UIImage imageNamed:@"Button_Determin_Right"] forState:UIControlStateNormal];
    [self addSubview:btn];
    [btn addTarget:self action:@selector(action_Recharge) forControlEvents:UIControlEventTouchUpInside];
    btn.layer.cornerRadius=10.0;
    btn.clipsToBounds=YES;
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.right.equalTo(self.mas_right).offset(-10);
        make.top.equalTo(self.mas_top).offset(20);
        make.height.mas_equalTo(40);
    }];
}
+(CGFloat)computeHeight:(id)info{
    return 60+100;
}

//给UILabel设置行间距和字间距
-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font {
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentLeft;
    paraStyle.lineSpacing = UILABEL_LINE_SPACE; //设置行间距
    paraStyle.hyphenationFactor = 1.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    //设置字间距 NSKernAttributeName:@1.5f
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@UILABEL_Kern_SPACE
                          };
    
    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
    label.attributedText = attributeStr;
}

@end

























